package com.connector.server.config;

import org.slf4j.LoggerFactory;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.ExecutorService;
import org.slf4j.Logger;

public class ExecutorProcessPool
{
    private static final Logger logger;
    private ExecutorService executor;
    private static ExecutorProcessPool pool;
    private final int threadMax = 25;

    private ExecutorProcessPool() {
        ExecutorProcessPool.logger.info("初始化线程池数量:{}",  25);
        this.executor = ExecutorServiceFactory.getInstance().createFixedThreadPool(25);
    }

    public static ExecutorProcessPool getInstance() {
        return ExecutorProcessPool.pool;
    }

    public void shutdown() {
        this.executor.shutdown();
    }

    public Future<?> submit(final Runnable task) {
        return this.executor.submit(task);
    }

    public Future<?> submit(final Callable<?> task) {
        return this.executor.submit(task);
    }

    public void execute(final Runnable task) {
        this.executor.execute(task);
    }

    static {
        logger = LoggerFactory.getLogger((Class)ExecutorProcessPool.class);
        ExecutorProcessPool.pool = new ExecutorProcessPool();
    }
}
